/*
  ZDROJE / SOURCES:

  http://delivery.acm.org/10.1145/1280000/1272705/p99-pelechano.pdf?ip=147.32.123.210&acc=ACTIVE%20SERVICE&CFID=232663601&CFTOKEN=51363755&__acm__=1355949581_ca80efb45b0266d31707c31a7730bc5b
  http://code.google.com/p/rascal-viewer/source/browse/trunk/Model+Viewer/assets/Legoman/LegoMan.obj?spec=svn5&r=5
  http://www.opengl.org/
  http://www.swiftless.com/tutorials/opengl4/1-opengl-window.html
  http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/
  http://www.opengl-tutorial.org/

 */

#ifndef _CAVE_
#include "main.h"
#endif

#include <glm/glm.hpp>
#include <GL/glew.h>
#include <GL/gl.h>
#include <vector>

#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

//#define NAMESTI

struct peon {
  int id;
  float x,y,z; //position
  float angle;
  float realAngle; //realAngle
  float speed; //speed
  float realSpeed; 

  int model;
  int checkPoint;
  bool flagMove;
  int colCount;
 };

 struct CheckPoint {
  float x,y;
  int id;
 };

struct DrawModel {
  float x,y,z,a;
  int idM;
};

struct OModel {
  GLuint Texture;
  GLuint TextureID ;

  std::vector<glm::vec3> vertices;
  std::vector<glm::vec2> uvs;
  std::vector<glm::vec3> normals; // Won't be used at the moment.

  GLuint vertexbuffer;
  GLuint uvbuffer;
};


/**
  OpenGLContext is a class designed to store all of your OpenGL functions and keep them
  out of the way of your application logic. Here we have the ability to create an OpenGL
  context on a given window and then render to that window.
*/
class OpenGLContext {
public:
  OpenGLContext(void); // Default constructor
#ifndef _CAVE_
  OpenGLContext(HWND hwnd); // Constructor for creating our context given a hwnd
#endif
  ~OpenGLContext(void); // Destructor for cleaning up our application
#ifndef _CAVE_
  bool create30Context(HWND hwnd); // Creation of our OpenGL 3.x context
#endif
  void setupScene(void); // All scene information can be setup here
#ifndef _CAVE_
  void reshapeWindow(int w, int h); // Method to get our window width and height on resize
#endif
  void renderScene(void); // Render scene (display method from previous OpenGL tutorials)
#ifndef _CAVE_
  void updateKeyboard(bool* key);
#endif
  void generatePeon();
  void updatePeon();
  void updateCam(int idBtn);

#ifndef _CAVE_
  void computeMatricesFromInputs();
#endif

  void setViewMatrix(const glm::mat4 mat);
  void setProjectionMatrix(const glm::mat4 mat);
private:
  glm::mat4 getViewMatrix() const;
  glm::mat4 getProjectionMatrix() const ;
  void drawModel(OModel& model, DrawModel p);
  void drawPeon(peon& p) const;

  glm::mat4 ViewMatrix;
  glm::mat4 ProjectionMatrix;
#ifndef _CAVE_
private:
  int windowWidth; // Store the width of our window
  int windowHeight; // Store the height of our window

protected:
  HGLRC hrc; // Rendering context
  HDC hdc; // Device context
  HWND hwnd; // Window identifier
#endif
};
